import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';

import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';

import 'package:exams_app/gen_a/A.dart';
import 'package:exams_app/home_module/exams_module/view.dart';
import 'package:exams_app/net/Address.dart';
import 'package:exams_app/net/persisten_storage.dart';
import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:get/get.dart';
import 'package:rtmp_publisher/camera.dart';
import 'dart:async';

import 'package:exams_app/home_module/exams_module/exams_complete_page.dart';
import 'package:exams_app/home_module/exams_module/aiface_page.dart';

import '../../main.dart';
import 'logic.dart';

import 'package:flutter_html/html_parser.dart';
// import 'package:rtmp_publisher/camera.dart';

// import 'package:rtmp_publisher_null_safe/camera.dart';



import 'package:disable_screenshots/disable_screenshots.dart';


// import 'package:camera_with_rtmp/camera.dart';

import 'dart:async';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:video_player/video_player.dart';
import 'package:wakelock/wakelock.dart';

import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:web_socket_channel/status.dart' as status;
import 'dart:convert' as convert;

import 'package:intl/intl.dart';
import 'package:flutter_ios_screenshots/flutter_ios_screenshots.dart';



class ExamsPage extends StatefulWidget {
  const ExamsPage({Key key}) : super(key: key);

  @override
  _ExamsPageState createState() => _ExamsPageState();
}

class _ExamsPageState extends State<ExamsPage>
    with SingleTickerProviderStateMixin, WidgetsBindingObserver {

  DisableScreenshots _plugin = DisableScreenshots();
  // 监控截屏行为的stream
  StreamSubscription<void> _screenshotsSubscription;
  int _screenshotsCount = 0;
  bool _disableScreenshots = false;


  final HomeModuleLogic logic = Get.put(HomeModuleLogic());

   int entercount = 0;

  static int backCount = 0;

  SwiperController _swController;


  // WebSocketChannel channel;

  var name;
  var uid;

  var rtm_url;


  /// 连接 socket

  // void connectSocket()async{
  //
  //
  //
  //   name = await PersistentStorage().getStorage('name');
  //   uid = await PersistentStorage().getStorage('uid');
  //
  //   Map<String, dynamic> b =  convert.jsonDecode('''
  //       {"user_id":${await PersistentStorage().getStorage('uid')},"user_name":"${await PersistentStorage().getStorage('name')}","code":2}
  //       ''');
  //
  //
  //   print('kkkkkkkkkkkkkkkkkkk ----------------- ${b}');
  //
  //
  //   channel.sink.add(
  //     convert.jsonEncode(b),
  //   );
  // }


  ///监测截屏
  void _listeningIosEndScreenshots() {
    FlutterIosScreenshots.listeningPlatform((Uint8List endResult) {
      // _image = true;
      // _image8List = endResult;

      print('+++++++++++++++++++++++++++++++++ 监听到iOS 截屏了');


      setState(() {});
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    print('断开了链接');


    // stopVideoStreaming();


    // channel.sink.close();

    // controller.dispose();


    // countdownTimer.cancel();
    // countdownTimer = null;

    cancelTimer();

    WidgetsBinding.instance.removeObserver(this);


    super.dispose();


    //取消截屏监控可以调用cancel()方法
    if (_screenshotsSubscription != null) {
      _screenshotsSubscription.cancel();
    }


    print('考试页面已经dispose');
  }


  // List<CameraDescription> cameras = [];

  CameraController controller;

  void initCamers() async {

    controller = CameraController(cameras[1], ResolutionPreset.low,enableAudio: false,androidUseOpenGL: true);

    try {
      await controller.initialize();

    } on CameraException catch (e) {
      // _showCameraException(e);
    }

    if (mounted) {
      setState(() {});
    }

  }


  /// 禁止截屏

  void initScreenshots()async{

    bool flag = !_disableScreenshots;

    await _plugin.disableScreenshots(flag);

    setState(() {
      _disableScreenshots = flag;
    });

  }

  var imageFile0 = '';

  var seconds = 5;


  Timer countdownTimer;

  Timer aifaceTimer;

  int countLaven = 0;

  /// 自动识别
  void savaPic()async{



    // print(' ============= 图片地址${filePath}');
    // print(' ============= 开始检测人脸角度状态');


    takePicture().then((filePath) {

      logic.requestDataWithAIfaceJiaodu(filePath).then((json)async{

        /// json['uid']

        if(json['error'] ==-1){
          countLaven++;

          var imageys = await imageCompressAndGetFile(File(imageFile0));

          List bytes = await imageys.readAsBytes();

          String bs64 = base64Encode(bytes);

          String bs64Image = bs64;

          logic.requestDataWithWeiGuiPic(bs64Image, logic.model.value.data[0].id);

          BotToast.showText(text: '请正视屏幕');

          if(countLaven > logic.model.value.data[0].leave){

            Get.snackbar('提示', '您已经离开app${countLaven}次,系统已经自动交卷');

            onStopButtonPressed();

            // stopVideoStreaming().then((value){
            //
            // });
            // WidgetsBinding.instance.removeObserver(this);

            BotToast.showText(text: '您已经离开app${countLaven}次,系统已经自动交卷');

            Get.offAll(ExamsCompletePage(logic.model.value.data[0].id,title: '考试结果',));
          }else if(json['error'] ==0){
            print('正常角度');
          }


        }else{
          print('正常角度');
        }

      });
    });
  }

  Future<String> takePicture() async {
    if (!controller.value.isInitialized) {
      Get.snackbar('提示','Error: select a camera first');
      return null;
    }
    final Directory extDir = await getApplicationDocumentsDirectory();
    final String dirPath = '${extDir.path}/Pictures/flutter_test';
    await Directory(dirPath).create(recursive: true);
    final String filePath = '$dirPath/${timestamp()}.jpg';

    if (controller.value.isTakingPicture) {
      // A capture is already pending, do nothing.
      return null;
    }

    try {
      imageFile0 = filePath;
      await controller.takePicture(filePath);
    } on CameraException catch (e) {

      return null;
    }

    return filePath;
  }



  void cancelTimer() {
    if (countdownTimer != null) {
      countdownTimer.cancel();
      countdownTimer = null;
    }
    if(aifaceTimer!=null){
      aifaceTimer.cancel();
      aifaceTimer = null;
    }

  }

  @override
  void initState() {

    //监测截屏
    _listeningIosEndScreenshots();

    WidgetsBinding.instance.addObserver(this);

    initScreenshots();

    _screenshotsSubscription = _plugin.onScreenShots.listen((event) {
      setState(() {
        BotToast.showText(text: '禁止截屏');
        _screenshotsCount++;
        print('+++++++++++++ ${_screenshotsCount}');
      });
    });


    initCamers();

    super.initState();

    _swController = SwiperController();
    _swController.index = 0;

    logic.requestDataWithExams('${logic.appHomeJson['data']['exam_id']}');


    logic.getrtmpUrlRequestData().then((value) {

      rtm_url = value['rtmpUrl'];

      print('rtmp: ==== ${rtm_url}');

    });

    // print('${logic.model.value.data[0].name}');

    // channel = IOWebSocketChannel.connect(Address.wsHost);

    // connectSocket();

    // channel.stream.listen((message) {
    //
    //   Map<String, dynamic> b =  convert.jsonDecode(message);
    //
    //   rtmp://36.153.159.19:1935/live/onBUNZsjbNVoMrHTl7c2TpaH7ZjuVvd69fc8ifpt7Rb5arr9
    //   print('kkkkkkkkkkkkkkkk++++++++++++++++++ ${message}');
    //
    //   if(b['code']==2){
    //
    //
    //     rtm_url = b['rtm_url'];
    //
    //     print('rtmp: ==== ${rtm_url}');
    //
    //     // print(b['u_count']);
    //     // u_count = b['u_count'];
    //     // jiantingjson = b;
    //
    //
    //
    //   }
    // });

    const timeout = const Duration(seconds: 3);
    print('currentTime='+DateTime.now().toString()); // 当前时间
    Timer(timeout, () {
      //callback function
      print('afterTimer='+DateTime.now().toString()); // 3s之后
      startVideoStreaming(rtm_url).then((String url) {
        if (mounted) setState(() {});
        if (url != null) print('Streaming video to $url');
        Wakelock.enable();

        ///循环执行
        ///间隔9秒
        countdownTimer = Timer.periodic(Duration(milliseconds: 10000), (timer) {

          savaPic();
          ///定时任务
        });

        /// 本人检测
        // aifaceTimer = Timer.periodic(Duration(milliseconds: 15000), (timer)async {
        //
        //   var imageys = await imageCompressAndGetFile(File(imageFile0));
        //
        //   List bytes = await imageys.readAsBytes();
        //
        //   String bs64 = base64Encode(bytes);
        //
        //   String bs64Image = 'data:image/jpg;base64,${bs64}';
        //
        //   logic.requestDataWithAIface(bs64Image).then((value) {
        //
        //     if(value['errcode']==-100){
        //       BotToast.showText(text: '摄像头内未检测到人脸');
        //     }else if(value['data']=='False'){
        //       BotToast.showText(text: '当前考试不是本人，请本人考试');
        //     }else if(value['data']=='True'){
        //       print('人脸检测成功,是本人');
        //     }
        //     else{
        //       print('未知');
        //       // BotToast.showText(text: '人脸检测成功');
        //     }
        //   });
        //   // takePicture().then((image) {
        //   //
        //   //
        //   //
        //   // });
        // });



        // Wakelock.enable();
      });
    });




  }


  List c;


  void didChangeAppLifecycleState(AppLifecycleState state) {
    print(" app 当前状态 -didChangeAppLifecycleState-" + state.toString());
    switch (state) {
      case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。

        break;
      case AppLifecycleState.resumed: //从后台切换前台，界面可见
        if (Get.isDialogOpen) {
          Get.back();
        }
        print('从后台切换前台');
        // Get.defaultDialog(title: '您已经离开app${entercount}次');
        if(entercount == 0){
          Get.snackbar('提示', '开始考试时,不得切屏或进入后台,超过${logic.model.value.data[0].leave}次将自动交卷');
          return;
        }

        if(entercount >= logic.model.value.data[0].leave){
          Get.snackbar('提示', '您已经离开app${entercount}次,系统已经自动交卷');

          onStopButtonPressed();

          // stopVideoStreaming().then((_) {

            // if(controller.value.isStreamingVideoRtmp){
            //   if (mounted) setState(() {});
            //   Get.snackbar('Video streamed to: $url','');
            // }else{
            //   if (mounted) setState(() {});
            //   Get.snackbar('Video streamed to: $url','');
            // }
          // });

          // Wakelock.disable();


          // countdownTimer.cancel();


          // WidgetsBinding.instance.removeObserver(this);


          Get.offAll(ExamsCompletePage(logic.model.value.data[0].id,title: '考试结果',));
        }else{

          Get.snackbar('提示', '您已经离开app${entercount}次');

        }

        break;
      case AppLifecycleState.paused: // 界面不可见，后台
        print('进入后台');

        entercount++;

        break;
      case AppLifecycleState.detached: // APP结束时调用
        break;
    }
  }

  // Widget customBackDig() {
  //   return Container(
  //     height: 100,
  //     width: 100,
  //     color: Colors.red,
  //   );
  // }



  Widget build(BuildContext context) {
    return GetBuilder<HomeModuleLogic>(
      builder: (logic) {
          return LayoutBuilder(builder: (BuildContext context,BoxConstraints constraints){
          print('constraints.maxHeight = ${constraints.maxHeight}');

          return WillPopScope(
              child: Scaffold(
                  backgroundColor: Colors.grey[200],
                  body: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(
                            top: MediaQueryData.fromWindow(window).padding.top),
                        width: Get.width,
                        // height: 100,
                        child: Stack(
                          children: [
                            Container(
                                padding: EdgeInsets.only(left: 15, top: 15),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Container(
                                      height: 44,
                                      width: 44,
                                      child: GestureDetector(
                                        onTap: () {
                                          Get.generalDialog(pageBuilder:
                                              (BuildContext context,
                                              Animation<double> animation,
                                              Animation<double>
                                              secondaryAnimation) {
                                            return Center(
                                                child: Material(
                                                  type: MaterialType.transparency,
                                                  child: Container(
                                                    decoration: new ShapeDecoration(
                                                        color: Colors.white,
                                                        shape:
                                                        new RoundedRectangleBorder(
                                                            borderRadius:
                                                            new BorderRadius
                                                                .all(new Radius
                                                                .circular(
                                                                5)))),
                                                    // margin: EdgeInsets.all(220),
                                                    height: 240,
                                                    width: 240,
                                                    child: Column(
                                                      children: [
                                                        SizedBox(
                                                          height: 25,
                                                        ),
                                                        Image.asset(
                                                            A.assets_waring_icon),
                                                        SizedBox(
                                                          height: 20,
                                                        ),
                                                        Text(
                                                          '您确定要返回吗?',
                                                          style: TextStyle(
                                                              fontSize: 18,
                                                              color:
                                                              HexColor('#333333'),
                                                              fontWeight:
                                                              FontWeight.w500),
                                                        ),
                                                        SizedBox(
                                                          height: 10,
                                                        ),
                                                        Text(
                                                          '返回即代表离开考试',
                                                          style: TextStyle(
                                                            fontSize: 14,
                                                            color:
                                                            HexColor('#999999'),
                                                          ),
                                                        ),
                                                        Container(
                                                          margin: EdgeInsets.only(
                                                              left: 5,
                                                              right: 5,
                                                              top: 15),
                                                          child: Row(
                                                            mainAxisAlignment:
                                                            MainAxisAlignment
                                                                .spaceAround,
                                                            children: [
                                                              RaisedButton(
                                                                shape:
                                                                RoundedRectangleBorder(
                                                                  borderRadius:
                                                                  BorderRadius
                                                                      .circular(
                                                                      5),
                                                                  side: BorderSide(
                                                                    width: 1,
                                                                    color: Theme.of(
                                                                        context)
                                                                        .primaryColor,
                                                                    style: BorderStyle
                                                                        .solid,
                                                                    // style: BorderStyle.none,
                                                                  ),
                                                                ),
                                                                child: Text(
                                                                  '确定',
                                                                  style: TextStyle(
                                                                      fontSize: 16,
                                                                      color: Colors
                                                                          .white),
                                                                ),
                                                                elevation: 0,
                                                                color:
                                                                Theme.of(context)
                                                                    .primaryColor,
                                                                onPressed: ()async {

                                                                  backCount++;
                                                                  print('backCount ========================  ${backCount}');

                                                                  if(backCount>=3){
                                                                    backCount=0;
                                                                    Get.offAll(ExamsCompletePage(logic.model.value.data[0].id,title: '考试结果',));
                                                                    // Get.snackbar('提示', '已经返回到${backCount}次');

                                                                  }


                                                                  // stopVideoStreaming().then((_) {

                                                                  // if(controller.value.isStreamingVideoRtmp){
                                                                  //   if (mounted) setState(() {});
                                                                  //   Get.snackbar('Video streamed to: $url','');
                                                                  // }else{
                                                                  //   if (mounted) setState(() {});
                                                                  //   Get.snackbar('Video streamed to: $url','');
                                                                  // }
                                                                  // });


                                                                  // countdownTimer.cancel();
                                                                  //
                                                                  // WidgetsBinding.instance.removeObserver(this);

                                                                  onStopButtonPressed();
                                                                  Get.offAll(HomeModulePage());


                                                                  // Get.to(HomeModulePage());

                                                                  // Get.offAll(page)

                                                                  // Navigator.of(
                                                                  //         context)
                                                                  //     .pushAndRemoveUntil(
                                                                  //         MaterialPageRoute(
                                                                  //             builder:
                                                                  //                 (context) =>
                                                                  //                     HomeModulePage()),
                                                                  //         (route) =>
                                                                  //             route ==
                                                                  //             null);
                                                                  // Get.back();
                                                                  // Get.back();
                                                                },
                                                              ),
                                                              RaisedButton(
                                                                shape:
                                                                RoundedRectangleBorder(
                                                                  borderRadius:
                                                                  BorderRadius
                                                                      .circular(
                                                                      5),
                                                                  side: BorderSide(
                                                                    width: 1,
                                                                    color: HexColor(
                                                                        '#D9D9D9'),
                                                                    style: BorderStyle
                                                                        .solid,
                                                                    // style: BorderStyle.none,
                                                                  ),
                                                                ),
                                                                child: Text('取消'),
                                                                elevation: 0,
                                                                color: Colors.white,
                                                                onPressed: () {
                                                                  Get.back();
                                                                  // _swController.
                                                                },
                                                              ),
                                                            ],
                                                          ),
                                                        )
                                                      ],
                                                    ),
                                                  ),
                                                ));
                                          });
                                        },
                                        child: Image.asset(A.assets_arrback_icon),
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 15),
                                      child: Text(
                                        '您正在被监控',
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: HexColor('#999999')),
                                      ),
                                    ),
                                    CountTextWidget(logic.model. value),
                                  ],
                                )),



                            Visibility(
                                visible: true,
                                child:Align(
                                  alignment: Alignment.topRight,
                                  child:  Container(
                                    margin: EdgeInsets.only(right: 10),
                                    decoration: BoxDecoration(
                                      color: Colors.white,
                                      border: Border.all(
                                        color: controller != null && controller.value.isRecordingVideo
                                            ? controller.value.isStreamingVideoRtmp
                                            ? Colors.redAccent
                                            : Colors.orangeAccent
                                            : controller != null &&
                                            controller.value.isStreamingVideoRtmp
                                            ? Colors.blueAccent
                                            : Colors.grey,
                                        width: 3.0,
                                      ),
                                    ),
                                    height: 120,
                                    width: 90,
                                    alignment: Alignment.centerRight,
                                    child: _cameraPreviewWidget(),
                                  ),
                                )
                            ),
                            // Visibility(
                            //     visible: true,
                            //     child:Align(
                            //       alignment: Alignment.topLeft,
                            //       child:  Container(
                            //         color: Colors.red,
                            //         margin: EdgeInsets.only(left: 10),
                            //         height: 50,
                            //         width: 50,
                            //         alignment: Alignment.centerRight,
                            //         child: Container(
                            //           child: Image.file(File(imageFile0)),
                            //         ),
                            //       ),
                            //     )
                            // ),

                            // GestureDetector(
                            //   onTap: ()async{
                            //     // if(controller.value.isStreamingVideoRtmp){
                            //     //
                            //     //   return;
                            //     // }
                            //     startVideoStreaming(rtm_url).then((String url) {
                            //       if (mounted) setState(() {});
                            //       // if (url != null) showInSnackBar('Streaming video to $url');
                            //       // Wakelock.enable();
                            //     });
                            //   },
                            //   child:   Container(
                            //
                            //     alignment: Alignment.centerRight,
                            //     child: Image.asset(A.assets_exbg),
                            //   ),
                            // ),
                          ],
                        ),
                        // child: Image.asset(A.assets_exbg),
                      ),
                      GetBuilder<HomeModuleLogic>(
                        builder: (logic) {
                          return Expanded(
                            child: ListView(
                              padding: EdgeInsets.all(0),
                              children: [
                                Container(
                                  // constraints: BoxConstraints(
                                  //   maxHeight: 500
                                  // ),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius: BorderRadius.circular(10.0),
                                  ),
                                  // color: Colors.white,
                                  margin: EdgeInsets.only(
                                      left: 15, right: 15, top: 10),
                                  height: 450,
                                  child:  Swiper(
                                    physics: new NeverScrollableScrollPhysics(),
                                    controller: _swController,
                                    loop: false,
                                    scrollDirection: Axis.horizontal,
                                    // 横向
                                    itemCount: logic
                                        .model.value.data[0].questionIds.length,
                                    // 数量
                                    autoplay: false,
                                    // 自动翻页
                                    pagination: SwiperCustomPagination(builder:
                                        (BuildContext context,
                                        SwiperPluginConfig config) {
                                      _swController.config = config;
                                      return Container(
                                        // color: Colors.red,
                                        margin: EdgeInsets.only(
                                            top: 5, right: 0, left: 0),
                                        padding: EdgeInsets.only(left: 15,right: 15),
                                        alignment: Alignment.topRight,
                                        width: Get.width,
                                        height: 40,
                                        child:Column(
                                          children: [
                                            Row(
                                              mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                              children: [
                                                Text(
                                                  '${logic.model.value.data[0].questionIds[_swController.config.activeIndex].method}',
                                                  style: TextStyle(
                                                      fontSize: 18,
                                                      fontWeight: FontWeight.w500),
                                                ),
                                                Row(
                                                  mainAxisAlignment:
                                                  MainAxisAlignment.end,
                                                  children: [
                                                    Text(
                                                      '${config.activeIndex + 1}',
                                                      style: TextStyle(
                                                          fontSize: 18,
                                                          fontWeight:
                                                          FontWeight.w500),
                                                    ),
                                                    Container(
                                                      padding:
                                                      EdgeInsets.only(top: 5),
                                                      child: Text(
                                                        '/${config.itemCount}',
                                                        style: TextStyle(
                                                            fontSize: 12,
                                                            fontWeight:
                                                            FontWeight.w500,
                                                            color: Colors.grey),
                                                      ),
                                                    ),
                                                  ],
                                                ),

                                              ],
                                            ),
                                          ],
                                        ),
                                      );
                                    }),
                                    itemBuilder:
                                        (BuildContext context, int index) {
                                      return Container(
                                        // color: Colors.blue,
                                          margin: EdgeInsets.only(top: 15,left: 5,right: 5),
                                          child: ListView(
                                            shrinkWrap: true,
                                            // physics: new NeverScrollableScrollPhysics(),
                                            padding: EdgeInsets.all(0),
                                            // crossAxisAlignment:
                                            // CrossAxisAlignment.start,
                                            children: [
                                              Container(
                                                margin: EdgeInsets.only(
                                                    top: 30, left: 10),
                                                child: Html(
                                                    data:'${ logic
                                                        .model
                                                        .value
                                                        .data[0]
                                                        .questionIds[index]
                                                        .name}'),
                                              ),
                                              ListView.builder(
                                                  padding: EdgeInsets.only(top: 10,left: 5,right: 5),
                                                  // physics:
                                                  // new NeverScrollableScrollPhysics(),
                                                  shrinkWrap: true,
                                                  itemCount: logic
                                                      .model
                                                      .value
                                                      .data[0]
                                                      .questionIds[_swController
                                                      .config.activeIndex]
                                                      .questionLines
                                                      .length,
                                                  itemBuilder:
                                                      (BuildContext context,
                                                      int index) {
                                                    QuestionLines model = logic
                                                        .model
                                                        .value
                                                        .data[0]
                                                        .questionIds[_swController
                                                        .config.activeIndex]
                                                        .questionLines[index];
                                                    return GestureDetector(
                                                      child: Container(
                                                        alignment:
                                                        Alignment.centerLeft,
                                                        child: Text(
                                                            '${model.aZ}、${model.name}'),
                                                        padding: EdgeInsets.only(
                                                            left: 15),
                                                        margin: EdgeInsets.only(
                                                            top: 5,
                                                            right: 5,
                                                            left: 5),
                                                        decoration: BoxDecoration(
                                                          border: new Border.all(
                                                              width: 1,
                                                              color: HexColor(
                                                                  '#EEEEEE')),
                                                          color: model.isSelect
                                                              ? HexColor('DFEBFF')
                                                              : HexColor(
                                                              '#FAFBFB'),
                                                          borderRadius:
                                                          BorderRadius
                                                              .circular(1.0),
                                                        ),
                                                        height: 50,
                                                      ),
                                                      onTap: () {
                                                        if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].method=='单选题'||logic.model.value.data[0].questionIds[_swController.config.activeIndex].method=='判断题'){
                                                          for (int i = 0; i < logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length; i++) {
                                                            logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect = false;
                                                          }
                                                          model.isSelect = true;

                                                        }
                                                        /// 多选题
                                                        else{
                                                          logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[index].isSelect=!logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[index].isSelect;
                                                        }

                                                        List b = List();
                                                        List idList = List();
                                                        if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].method=='多选题'){

                                                          for(int i = 0;i<logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length;i++){
                                                            if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect==true){
                                                              b.add(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ);
                                                              idList.add(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].id);
                                                            }
                                                          }
                                                          List a = logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionIds;

                                                          a.sort((a,b){
                                                            return a-b;
                                                          });

                                                          idList.sort((a,b){
                                                            return a-b;
                                                          });

                                                          if(idList.join(',') == a.join(',')){
                                                            logic.requestDataWithTiJiao(b.join(','), true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                          }else{
                                                            logic.requestDataWithTiJiao(b.join(','), false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                          }
                                                          // if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionIds == idList){
                                                          //
                                                          //   logic.requestDataWithTiJiao(b.join(','), true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                          // }else{
                                                          //   logic.requestDataWithTiJiao(b.join(','), false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                          // }
                                                        }

                                                        /// 单选
                                                        else {

                                                          for(int i = 0;i<logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length;i++){
                                                            if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect==true){
                                                              // print(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ);
                                                              // print(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].id);
                                                              if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionIds.contains(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].id)){
                                                                logic.requestDataWithTiJiao(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ, true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                              }else{
                                                                logic.requestDataWithTiJiao(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ, false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);

                                                              }
                                                            }
                                                          }

                                                          // for (int i = 0; i < logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length; i++) {
                                                          //   if ( logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect==true) {
                                                          //     logic.requestDataWithTiJiao(model.aZ, true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);

                                                          // }


                                                          // else {
                                                          //
                                                          //   logic.requestDataWithTiJiao(model.aZ, false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                          // }
                                                          // }
                                                        }

                                                        setState(() {});
                                                      },
                                                    );
                                                  }),
                                              Container(
                                                margin: EdgeInsets.only(
                                                    left: 5, right: 5, top: 15),
                                                child: Row(
                                                  mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceAround,
                                                  children: [
                                                    RaisedButton(
                                                      shape:
                                                      RoundedRectangleBorder(
                                                        borderRadius:
                                                        BorderRadius.circular(
                                                            5),
                                                        side: BorderSide(
                                                          width: 1,
                                                          color:
                                                          HexColor('#D9D9D9'),
                                                          style:
                                                          BorderStyle.solid,
                                                          // style: BorderStyle.none,
                                                        ),
                                                      ),
                                                      child: Text('上一题'),
                                                      elevation: 0,
                                                      color: Colors.white,
                                                      onPressed: () {
                                                        print(
                                                            _swController.index);
                                                        _swController.previous(
                                                            animation: false);
                                                        // _swController.
                                                      },
                                                    ),
                                                    RaisedButton(
                                                      shape:
                                                      RoundedRectangleBorder(
                                                        borderRadius:
                                                        BorderRadius.circular(
                                                            5),
                                                        side: BorderSide(
                                                          width: 1,
                                                          color: Theme.of(context)
                                                              .primaryColor,
                                                          style:
                                                          BorderStyle.solid,
                                                          // style: BorderStyle.none,
                                                        ),
                                                      ),
                                                      child: Text(logic
                                                          .model
                                                          .value
                                                          .data[0]
                                                          .questionCount ==
                                                          _swController.config
                                                              .activeIndex +
                                                              1?'提交试卷':
                                                      '下一题',
                                                        style: TextStyle(
                                                            fontSize: 16,
                                                            color: Colors.white),
                                                      ),
                                                      elevation: 0,
                                                      color: Theme.of(context)
                                                          .primaryColor,
                                                      onPressed: () {
                                                        // List b = List();
                                                        // List idList = List();
                                                        // if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].method=='多选题'){
                                                        //
                                                        //   for(int i = 0;i<logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length;i++){
                                                        //     if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect==true){
                                                        //       b.add(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ);
                                                        //       idList.add(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].id);
                                                        //     }
                                                        //   }
                                                        //   List a = logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionIds;
                                                        //
                                                        //   a.sort((a,b){
                                                        //     return a-b;
                                                        //   });
                                                        //
                                                        //   idList.sort((a,b){
                                                        //     return a-b;
                                                        //   });
                                                        //
                                                        //   if(idList.join(',') == a.join(',')){
                                                        //     logic.requestDataWithTiJiao(b.join(','), true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //   }else{
                                                        //     logic.requestDataWithTiJiao(b.join(','), false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //   }
                                                        //   // if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionIds == idList){
                                                        //   //
                                                        //   //   logic.requestDataWithTiJiao(b.join(','), true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //   // }else{
                                                        //   //   logic.requestDataWithTiJiao(b.join(','), false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //   // }
                                                        // }
                                                        //
                                                        // /// 单选
                                                        // else {
                                                        //
                                                        //   for(int i = 0;i<logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length;i++){
                                                        //     if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect==true){
                                                        //       // print(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ);
                                                        //       // print(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].id);
                                                        //       if(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionIds.contains(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].id)){
                                                        //         logic.requestDataWithTiJiao(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ, true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //       }else{
                                                        //         logic.requestDataWithTiJiao(logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].aZ, false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //
                                                        //       }
                                                        //     }
                                                        //   }
                                                        //
                                                        //   // for (int i = 0; i < logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines.length; i++) {
                                                        //   //   if ( logic.model.value.data[0].questionIds[_swController.config.activeIndex].questionLines[i].isSelect==true) {
                                                        //   //     logic.requestDataWithTiJiao(model.aZ, true, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //
                                                        //   // }
                                                        //
                                                        //
                                                        //   // else {
                                                        //   //
                                                        //   //   logic.requestDataWithTiJiao(model.aZ, false, logic.model.value.data[0].questionIds[_swController.config.activeIndex].id);
                                                        //   // }
                                                        //   // }
                                                        // }

                                                        if (logic
                                                            .model
                                                            .value
                                                            .data[0]
                                                            .questionCount ==
                                                            _swController.config
                                                                .activeIndex +
                                                                1) {
                                                          print('答题结束');

                                                          logic.requestDataWith_api_no_exam(logic.model.value.data[0].id).then((value) {

                                                            Get.generalDialog(pageBuilder:
                                                                (BuildContext
                                                            context,
                                                                Animation<
                                                                    double>
                                                                animation,
                                                                Animation<
                                                                    double>
                                                                secondaryAnimation) {
                                                              return Center(
                                                                  child: Material(
                                                                    type: MaterialType
                                                                        .transparency,
                                                                    child: Container(
                                                                      decoration: new ShapeDecoration(
                                                                          color: Colors
                                                                              .white,
                                                                          shape: new RoundedRectangleBorder(
                                                                              borderRadius: new BorderRadius
                                                                                  .all(new Radius
                                                                                  .circular(
                                                                                  5)))),
                                                                      // margin: EdgeInsets.all(220),
                                                                      height: 240,
                                                                      width: 240,
                                                                      child: Column(
                                                                        children: [
                                                                          SizedBox(
                                                                            height: 25,
                                                                          ),
                                                                          Image.asset(A
                                                                              .assets_suc),
                                                                          SizedBox(
                                                                            height: 20,
                                                                          ),
                                                                          Text(
                                                                            '确定提交试卷么?',
                                                                            style: TextStyle(
                                                                                fontSize:
                                                                                18,
                                                                                color: HexColor(
                                                                                    '#333333'),
                                                                                fontWeight:
                                                                                FontWeight.w500),
                                                                          ),
                                                                          SizedBox(
                                                                            height: 10,
                                                                          ),
                                                                          Text(
                                                                            value['data']==0?'您已完成考试':
                                                                            '还有${value['data'].toString()}道题未答,是否继提交试卷',
                                                                            style:
                                                                            TextStyle(
                                                                              fontSize:
                                                                              14,
                                                                              color: HexColor(
                                                                                  '#999999'),
                                                                            ),
                                                                          ),
                                                                          Container(
                                                                            margin: EdgeInsets.only(
                                                                                left: 5,
                                                                                right:
                                                                                5,
                                                                                top:
                                                                                15),
                                                                            child: Row(
                                                                              mainAxisAlignment:
                                                                              MainAxisAlignment
                                                                                  .spaceAround,
                                                                              children: [
                                                                                RaisedButton(
                                                                                  shape:
                                                                                  RoundedRectangleBorder(
                                                                                    borderRadius:
                                                                                    BorderRadius.circular(5),
                                                                                    side:
                                                                                    BorderSide(
                                                                                      width: 1,
                                                                                      color: Theme.of(context).primaryColor,
                                                                                      style: BorderStyle.solid,
                                                                                      // style: BorderStyle.none,
                                                                                    ),
                                                                                  ),
                                                                                  child:
                                                                                  Text(
                                                                                    '确定',
                                                                                    style:
                                                                                    TextStyle(fontSize: 16, color: Colors.white),
                                                                                  ),
                                                                                  elevation:
                                                                                  0,
                                                                                  color:
                                                                                  Theme.of(context).primaryColor,
                                                                                  onPressed:
                                                                                      () {

                                                                                    // WidgetsBinding.instance.removeObserver(this);

                                                                                    onStopButtonPressed();

                                                                                    // stopVideoStreaming().then((value) {
                                                                                    //
                                                                                    // });


                                                                                    Get.offAll(ExamsCompletePage(logic.model.value.data[0].id,title: '考试结果',));
                                                                                  },
                                                                                ),
                                                                                RaisedButton(
                                                                                  shape:
                                                                                  RoundedRectangleBorder(
                                                                                    borderRadius:
                                                                                    BorderRadius.circular(5),
                                                                                    side:
                                                                                    BorderSide(
                                                                                      width: 1,
                                                                                      color: HexColor('#D9D9D9'),
                                                                                      style: BorderStyle.solid,
                                                                                      // style: BorderStyle.none,
                                                                                    ),
                                                                                  ),
                                                                                  child:
                                                                                  Text('取消'),
                                                                                  elevation:
                                                                                  0,
                                                                                  color:
                                                                                  Colors.white,
                                                                                  onPressed:
                                                                                      () {
                                                                                    Get.back();
                                                                                    // _swController.
                                                                                  },
                                                                                ),
                                                                              ],
                                                                            ),
                                                                          )
                                                                        ],
                                                                      ),
                                                                    ),
                                                                  ));
                                                            });

                                                          });



                                                          return;
                                                        }
                                                        _swController.next(
                                                            animation: false);

                                                      },
                                                    )
                                                  ],
                                                ),
                                              )
                                            ],
                                          )
                                      );
                                    },
                                  ),
                                ),
                                BottonWidget(
                                    logic.model.value.data[0].questionIds,
                                    _swController),
                              ],
                            ),
                          );
                        },
                      )
                    ],
                  )


              ),
              onWillPop: () async {
                Get.generalDialog(pageBuilder: (BuildContext context,
                    Animation<double> animation,
                    Animation<double> secondaryAnimation) {
                  return Center(
                      child: Material(
                        type: MaterialType.transparency,
                        child: Container(
                          decoration: new ShapeDecoration(
                              color: Colors.white,
                              shape: new RoundedRectangleBorder(
                                  borderRadius:
                                  new BorderRadius.all(new Radius.circular(5)))),
                          // margin: EdgeInsets.all(220),
                          height: 240,
                          width: 240,
                          child: Column(
                            children: [
                              SizedBox(
                                height: 25,
                              ),
                              Image.asset(A.assets_waring_icon),
                              SizedBox(
                                height: 20,
                              ),
                              Text(
                                '您确定要返回吗?',
                                style: TextStyle(
                                    fontSize: 18,
                                    color: HexColor('#333333'),
                                    fontWeight: FontWeight.w500),
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Text(
                                '返回即代表离开考试',
                                style: TextStyle(
                                  fontSize: 14,
                                  color: HexColor('#999999'),
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(left: 5, right: 5, top: 15),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                                  children: [
                                    RaisedButton(
                                      shape: RoundedRectangleBorder(
                                        borderRadius: BorderRadius.circular(5),
                                        side: BorderSide(
                                          width: 1,
                                          color: Theme.of(context).primaryColor,
                                          style: BorderStyle.solid,
                                          // style: BorderStyle.none,
                                        ),
                                      ),
                                      child: Text(
                                        '确定',
                                        style: TextStyle(
                                            fontSize: 16, color: Colors.white),
                                      ),
                                      elevation: 0,
                                      color: Theme.of(context).primaryColor,
                                      onPressed: () {
                                        // controller.stopImageStream();
                                        // stopVideoStreaming().then((value){
                                        //
                                        // });
                                        // WidgetsBinding.instance.removeObserver(this);

                                        backCount++;
                                        print('backCount ========================  ${backCount}');

                                        if(backCount>=3){
                                          backCount=0;
                                          Get.offAll(ExamsCompletePage(logic.model.value.data[0].id,title: '考试结果',));
                                          // Get.snackbar('提示', '已经返回到${backCount}次');

                                        }

                                        onStopButtonPressed();

                                        Get.offAll(HomeModulePage());

                                        // Navigator.of(context).pushAndRemoveUntil(
                                        //     MaterialPageRoute(
                                        //         builder: (context) =>
                                        //             HomeModulePage()),
                                        //     (route) => route == null);
                                      },
                                    ),
                                    RaisedButton(
                                      shape: RoundedRectangleBorder(
                                        borderRadius: BorderRadius.circular(5),
                                        side: BorderSide(
                                          width: 1,
                                          color: HexColor('#D9D9D9'),
                                          style: BorderStyle.solid,
                                          // style: BorderStyle.none,
                                        ),
                                      ),
                                      child: Text('取消'),
                                      elevation: 0,
                                      color: Colors.white,
                                      onPressed: () {
                                        Get.back();
                                        // _swController.
                                      },
                                    ),
                                  ],
                                ),
                              ),

                            ],
                          ),
                        ),
                      ));
                });
                return false;
              });
        });
      },
    );
  }

  String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();
  String url;
  String videoPath;


  Future<String> startVideoStreaming(var rtm_url) async {
    if (controller == null) {
      return null;
    }
    if (!controller.value.isInitialized) {
      // showInSnackBar('Error: select a camera first.');
      return null;
    }

    if (controller.value.isStreamingVideoRtmp) {
      return null;
    }

    // Open up a dialog for the url
    // String myUrl = await _getUrl();
    try {
      // if (_timer != null) {
      //   _timer.cancel();
      //   _timer = null;
      // }
      url = rtm_url;
      await controller.startVideoStreaming(rtm_url);
      // _timer = Timer.periodic(Duration(seconds: 1), (timer) async {
      //   var stats = await controller.getStreamStatistics();
      //   // print(stats);
      // });
    } on CameraException catch (e) {
      // _showCameraException(e);
      return null;
    }
    return url;
  }

  void onStopButtonPressed() {
    if (this.controller.value.isStreamingVideoRtmp) {
      stopVideoStreaming().then((_) {
        if (mounted) setState(() {});

      });
    } else {
      stopVideoRecording().then((_) {
        if (mounted) setState(() {});
      });
    }
  }

  Future<void> stopVideoRecording() async {
    if (!controller.value.isRecordingVideo) {
      return null;
    }

    try {
      await controller.stopVideoRecording();
    } on CameraException catch (e) {

      return null;
    }

  }

  Future<void> stopVideoStreaming() async {

    if (controller == null || !controller.value.isInitialized) {
      return;
    }
    if (!controller.value.isStreamingVideoRtmp) {
      return;
    }

    try {
      await controller.stopVideoStreaming();
      await controller.stopVideoRecording();

    } on CameraException catch (e) {
      // _showCameraException(e);
      return null;
    }
  }

  Widget _cameraPreviewWidget() {
    if (controller == null || !controller.value.isInitialized) {
      return const Text(
        'Tap a camera',
        style: TextStyle(
          color: Colors.white,
          fontSize: 24.0,
          fontWeight: FontWeight.w900,
        ),
      );
    } else {
      return GestureDetector(
        onTap: ()async{
        },
        child: AspectRatio(
          aspectRatio: controller.value.aspectRatio,
          child: CameraPreview(
            controller,
          ),
        ),
      );
    }
  }
}

class CountTextWidget extends StatefulWidget {

  ExamsModel model;

  CountTextWidget(this.model);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return CountTextWidgetState();
  }
}

class CountTextWidgetState extends State<CountTextWidget> {

  final HomeModuleLogic logic = Get.put(HomeModuleLogic());


  int seconds1 = 10;

  Timer _timer;

  void cancelTimer() {
    if (_timer != null) {
      _timer.cancel();
      _timer = null;
    }
  }

  void startTimer() {
    //设置 1 秒回调一次
    const period = const Duration(seconds: 1);
    _timer = Timer.periodic(period, (timer) {
      //更新界面
      setState(() {
        //秒数减一，因为一秒回调一次
        seconds1--;
//        print('我在更新界面>>>>>>>>>>>>>> $seconds');
//         countContent = constructTime(seconds);
      });
      if (seconds1 == 0) {
        //倒计时秒数为0，取消定时器
        print('我被取消了  ');
        BotToast.showText(text: '考试时间到');
        cancelTimer();
        Get.offAll(ExamsCompletePage(logic.model.value.data[0].id,title: '考试结果',));

        // getData();
      }
    });
  }

  @override
  void dispose() {
    cancelTimer();
    super.dispose();

  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    // print(widget.model.data[0].seconds);
    //
    // String i = widget.model.data[0].seconds.toStringAsFixed(0);
    // var i1 = int.parse(i);
    // seconds1 = i1;


    DateTime now = DateTime.parse(widget.model.data[0].dateEnd);

    String formattedDate = DateFormat('yyyy-MM-dd-HH-mm-ss').format(now);

    var s = formattedDate.split('-');


    // print('ssssssssssssssssssssssssssssssssss ${s.toString()}');

    LogUtil.e('////////////////// ${s.toString()}');

    var endtDate = new DateTime(int.parse(s[0]),int.parse(s[1]),int.parse(s[2]),int.parse(s[3]),int.parse(s[4]),int.parse(s[5]));
    var nowDate = new DateTime.now();
    var sec = endtDate.difference(nowDate).inSeconds;


    // seconds1 = widget.model.data[0].end_seconds;
    seconds1 = sec;


    startTimer();
  }

  //时间格式化，根据总秒数转换为对应的 hh:mm:ss 格式
  static String constructTime(int seconds) {
    int day = seconds ~/ 3600 ~/ 24;
    int hour = seconds ~/ 3600;
    int minute = seconds % 3600 ~/ 60;
    int second = seconds % 60;
    // if (day != 0) {
    //   return '$day天$hour小时$minute分$second秒后自动取消';
    // } else if (hour != 0) {
    //   return '$hour小时$minute分$second秒后自动取消';
    // } else if (minute != 0) {
    //   return '$minute分$second秒后自动取消';
    // } else if (second != 0) {
    //   return '$second秒后自动取消';
    // }
    // else {
    //   return '';
    // }
    return formatTime(hour) +
        ":" +
        formatTime(minute) +
        ":" +
        formatTime(second) +
        '';
  }

  //数字格式化，将 0~9 的时间转换为 00~09
  static String formatTime(int timeNum) {
    return timeNum < 10 ? "0" + timeNum.toString() : timeNum.toString();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Text(
      '${constructTime(seconds1)}',
      style: TextStyle(
          fontSize: 32,
          color: HexColor('#333333'),
          fontWeight: FontWeight.w500),
    );
  }
}




class BottonWidget extends StatefulWidget {

  List<QuestionIds> model;
  SwiperController swiperController;

  BottonWidget(this.model, this.swiperController);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return BottonWidgetState();
  }
}

class BottonWidgetState extends State<BottonWidget> {

  HomeModuleLogic logic = Get.find();

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(left: 20, top: 15, right: 15),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  '答题情况',
                  style: TextStyle(fontSize: 16, color: HexColor('#333333')),
                ),
                Row(
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Image.asset(A.assets_yida),
                        Text(
                          '已答',
                          style: TextStyle(
                              color: Theme.of(context).primaryColor,
                              fontSize: 12),
                        ),
                      ],
                    ),
                    SizedBox(
                      width: 5,
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Image.asset(A.assets_weida),
                        Text(
                          '未答',
                          style: TextStyle(
                              color: HexColor('#999999'), fontSize: 12),
                        ),
                      ],
                    ),
                  ],
                )
              ],
            ),
          ),
          GridView.builder(
            physics: new NeverScrollableScrollPhysics(),
              padding: EdgeInsets.all(20),
              shrinkWrap: true,
              itemCount: widget.model.length,
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  //横轴元素个数
                  crossAxisCount: 10,
                  //纵轴间距
                  mainAxisSpacing: 15.0,
                  //横轴间距
                  crossAxisSpacing: 5.0,
                  //子组件宽高长度比例
                  childAspectRatio: 1.0),
              itemBuilder: (BuildContext context, int index) {
                return GestureDetector(
                  onTap: () {
                    widget.swiperController.move(index, animation: false);

                    print('${index}');
                  },
                  child: Container(
                    padding: EdgeInsets.all(5),
                    alignment: Alignment.center,
                    height: 50,
                    width: 50,
                    decoration: BoxDecoration(
                      color: widget.model[index].answer.toString() == 'false'||widget.model[index].answer.toString() ==''
                          ? Colors.white
                          : Theme.of(context).primaryColor,
                      borderRadius: BorderRadius.circular(25),
                    ),
                    child: Text(
                      '${index + 1}',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          color: widget.model[index].answer.toString() == 'false'||widget.model[index].answer.toString() ==''
                              ? Colors.grey
                              : Colors.white),
                    ),
                  ),
                );
              }),
        ],
      ),
    );
  }
}
